import java.util.Hashtable;
import java.util.StringTokenizer;


class P119_39643 {

	public static void main(String[] args) {
		String line = readLn();
		
		while (line != null) {
			process(Integer.parseInt(line));
			
			line = readLn();
			
			if (line != null) System.out.println();
		}
		
	}
	
	private static void process(int i) {
		Person[] people = new Person[i];
		Hashtable peopleMap = new Hashtable();
		
		StringTokenizer st = new StringTokenizer(readLn());
		
		for (int k = 0; k < i; k++) {
			String name = st.nextToken();
			people[k] = new Person(name);
			peopleMap.put(name, people[k]);
		}
		
		
		for (int k = 0; k < i; k++) {
			
			st = new StringTokenizer(readLn());
			String giverName = st.nextToken();
			Person person = (Person)peopleMap.get(giverName);
			int amountGiven = Integer.parseInt(st.nextToken());
			int dividedBy = Integer.parseInt(st.nextToken());
			person.gift =  person.gift - (dividedBy != 0 ? ((amountGiven / dividedBy) * dividedBy ) : 0 );
			int amountReceived = (dividedBy != 0 ? (amountGiven / dividedBy) : 0 );
			
			for (int j = 0; j < dividedBy; j++) {
				String receiverName = st.nextToken();
				person = (Person)peopleMap.get(receiverName);
				person.gift = person.gift + amountReceived; 
			}
			
		}
		
		for (int k = 0; k < i; k++) {
			System.out.println(people[k].name + " " + people[k].gift);
		}
		
	}

	static String readLn() {
	       String newLine = System.getProperty("line.separator");
	       StringBuffer buffer = new StringBuffer();
	       int car = -1;
	       try {
	           car = System.in.read();
	           while ((car > 0) && (car != newLine.charAt(0))) {
	               buffer.append((char)car);
	               car = System.in.read();
	           }
	           if (car == newLine.charAt(0))
	           System.in.skip(newLine.length() - 1);
	       } catch (java.io.IOException e) { return (null);}
	       if ((car < 0) && (buffer.length() == 0)) return (null);
	      return (buffer.toString()).trim();
	 }
	
}


class Person {
	
	public Person(String name) {
		this.name = name;
	}
	String name;
	int gift;
}